<template>
  <div>
    <el-card class="box-cardd" style="margin-left: 25px">
      <el-table
          border
          text-align:
          center
          :cell-style="{ padding: '7px'}"
          :data="tableData"
          style="width: 100%"
          @selection-change="handleSelectionChange"
      >
        <el-table-column width="170" prop="id" label="病人序号"></el-table-column>
        <!--        <el-table-column prop="userAccount" label="病人账号"> </el-table-column>-->
        <el-table-column width="170" prop="name" label="病人姓名"></el-table-column>
        <el-table-column width="170" prop="gender_name" label="性别"></el-table-column>
        <el-table-column width="170" prop="illness_desc" label="病情描述"></el-table-column>
        <el-table-column width="170" prop="department_type_name" label="预约科室类型">
        </el-table-column>
        <el-table-column width="170" prop="department_name" label="预约科室名称">
        </el-table-column>
        <el-table-column width="170" prop="doctor_name" label="预约医生"></el-table-column>
        <el-table-column width="170" prop="subscribe_time" label="预约时间"></el-table-column>
        <el-table-column label="诊断">
          <template slot-scope="scope">
            <el-button
                el-button
                type="primary"
                icon="el-icon-edit"
                circle
                @click="diagnosis(scope.row)"
                size="small"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <div style="margin-top: 80px;margin-left: 10px"><span v-if="judge" style="color: red">注:     当前还未收到预约您的用户</span></div>
    <el-pagination
        background
        layout="prev, pager, next,total"
        :total=departmentPageDto
        :page-size=filter.size
        style="margin-left: 600px; margin-top: 30px"
        @current-change="handleCurrentChange">
    </el-pagination>
  </div>
</template>

<script>
export default {
  mounted() {
    window.Vue = this;
  },
  data() {
    return {
      tableData: [{
        id:'',
        userAccount:'',
        name:'',
        gender_name:'',
        illness_desc:'',
        department_type_name:'',
        department_name:'',
        doctor_name:'',
        subscribe_time:''
      }],
      user: {},
      departmentPageDto: null,
      filter: {
        size: 3,       // 单页数据量
        page: 5,
      },
      judge: true
    };
  },
  created() {
    this.user = this.$getSessionStorage("user");
    this.patientRegister();
  },
  filters: {
    formatDate: function (value) {
      var dt = new Date(value)
      let year = dt.getFullYear();
      let month = dt.getMonth() + 1;
      let date = dt.getDate();
      return `${year}-${month}-${date}`
    }
  },
  methods: {
    diagnosis(row) {
      this.$confirm("确认诊断" + row.name + "病人？")
          .then((_) => {
            //axios医生信息入挂号表请求
            this.$axios
                .post("/register/addDoctorInformationById", {
                  id: row.id,
                  docAccount: this.user.userName,
                  docType: this.user.userType,
                })
                .then((Response) => {
                  if (Response.data == "SUCCESS") {
                    console.log("医生信息已录入挂号表");
                  }
                })
                .catch((error) => {
                  console.error(error);
                });
            this.$router.push({
              path: "/index/toDoctorDiagnosis",
              query: {row: row},
            });
          })
          .catch((_) => {
          });
    },
    patientRegister() {
      console.log(this.user.name)
      //axios查询当前登陆人被预约请求
      this.$axios
          .get(this.$settings.BASE_URL + "registered/registerinfo/", {
            params: {doctor_name: this.user.name},
          })
          .then((Response) => {
            console.log(Response.data)
            console.log(Response.data.info_list)
            console.log(Response.data.info_list.count)

            console.log(this.user.name)
            if (Response.data.info_list.count === 0) {
              this.judge = true
            }else{
              this.judge = false
            }
            this.tableData = Response.data.info_list.results;
            this.departmentPageDto = Response.data.info_list.count;
            // this.tableData.subscribe_time = this.formatDate(this.tableData.subscribe_time)
            // console.log(this.tableData.subscribe_time)
          })
          .catch((error) => {
            console.error(error);
          });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
      console.log(val);
    },
    // 当前页
    handleCurrentChange(pageNumber) {
      // console.log(pageNumber,'>>>>>')
      this.select(pageNumber);
    },
    select(pageNum) {
      // var statusResult = this.formInline.status;
      // if (statusResult.indexOf("已缴费") >= 0) {
      //   statusResult = "已缴费";
      // }
      //axios查询科室列表请求((分页有参))
      var a = isNaN(pageNum);
      // false
      console.log(a,'>>>>a>>>>');
      if (a === true) {
        console.log('>>>>>is>>>>>')
        pageNum = 1;
      }
      this.filter.page = pageNum
      this.$axios
          // .get(this.$settings.BASE_URL + `outpatient/patientgetvue/?doctor=${this.formInline.doctor}&department=${this.formInline.department}`, {
          //   params: this.filter,
          //   // status: statusResult,
          /*})
          .then((Response) => {
            console.log(this.formInline.department)
            this.tableData = Response.data.infos.results;
            this.departmentPageDto = Response.data.infos.count;
          })
          .catch((error) => {
            console.error(error);
          });*/
      .get(this.$settings.BASE_URL + "registered/registerinfoview/", {
            params: {page: this.filter.page},
          })
          .then((Response) => {
            console.log(Response.data)
            console.log(Response.data.info_list)
            console.log(Response.data.info_list.count)

            console.log(this.user.name)
            if (Response.data.info_list.count === 0) {
              this.judge = true
            }else{
              this.judge = false
            }
            this.tableData = Response.data.info_list.results;
            this.departmentPageDto = Response.data.info_list.count;
            // this.tableData.subscribe_time = this.formatDate(this.tableData.subscribe_time)
            // console.log(this.tableData.subscribe_time)
          })
          .catch((error) => {
            console.error(error);
          });
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  padding: 18px 0;
}

.box-cardd {
  margin-top: 30px;
  width: 1600px;
}
</style>